import cookie from './cookie.js'

let store = {
	//	本地Storage里获取用户数据
	getStorageData() {
		let arr = uni.getStorageInfoSync().keys || [];
		let data = {};
		arr.forEach((key) => {
			if (key.indexOf("sp") != -1) {
				data[key.slice(3)] = uni.getStorageSync(`${key}`);
			}
		});
		console.log("getStorageData===>>>", data);
		return data;
	},

	//	存储数据到Storage里
	setStorageData(data) {
		console.log(data, "data")
		let arr = Object.keys(data);
		arr.forEach((key) => {
			uni.setStorageSync(`sp_${key}`, data[key]);
		});
		console.log("setStorageData===>>>", uni.getStorageInfoSync());
	},
	
	handleCopy(val, id) {
		uni.setClipboardData({
			data: val,
			success(res) {
				uni.showToast({
					title: `${id===0?'下载链接复制成功,请在浏览器打开下载':'复制成功'}`,
					icon: "none",
					duration: 1500
				});
			}
		});
	},
	
	checkAuthority(code){
		let authList = JSON.parse(cookie.get('auth_list'))
		console.log('authList----' , authList)
		
		
		let authIndex = authList.findIndex((item)=> item == code) 
		if (authIndex == -1){
			uni.showToast({
				title:'暂无此权限，请联系店长',
				icon:'none'
			})
			return false
		}
		return true
	}
	
	
	
}

export default store;
